<?php


namespace app\api\library;


use app\common\library\Queues;
use think\Exception;

class Curl
{
    public static function posts($client, $data, $key)
    {
        $qd_url = 'https://api.reservation.inhct.cn/front/appoint/create';
        try {
            $res = $client->post($qd_url, ['json' => $data]);
            if ($res->getStatusCode() != 200) {
                throw new Exception('请求异常，httpCode=' . $res->getStatusCode());
            }
            $result = json_decode($res->getBody()->getContents(), true);
            if ($result['code'] == 20000) {
                $aData = [
                    'openid'    => 'o4QC4wBr-sGPqGJO7AgfGm5J1GjQ',
                    'zhandian'  => $key. '抢票成功'
                ];
                Queues::now('remind', $aData);
//                WxTemp::remind($aData);
                return true;
            }
//            elseif ($result['code'] == 40004) {
//                Cache::set($key, 1);
//                return true;
//            }
        } catch (\Exception $e){
            return false;
        }
        return false;
    }
}